//
//  Kylin_TopicPictureView.m
//  03-BuDeJie
//
//  Created by Kylin on 16/3/3.
//  Copyright © 2016年 kylin. All rights reserved.
//

#import "Kylin_TopicPictureView.h"
#import "Kylin_TopicItem.h"
#import "Kylin_SeeBigPictureViewController.h"

@interface Kylin_TopicPictureView()
@property (weak, nonatomic) IBOutlet UIImageView *gifView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIButton *seeBigPictureButton;

@end
@implementation Kylin_TopicPictureView

// 从xib中加载时添加手势
- (void)awakeFromNib{
    self.imageView.userInteractionEnabled = YES;
    [self.imageView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(seeBigPicture)]];
}

- (void)setTopicItem:(Kylin_TopicItem *)topicItem{
    
    _topicItem = topicItem;
    
    [self.imageView Kylin_setLargeImageUrl:topicItem.image1 smallImageUrl:topicItem.image0 placeholder:[UIImage imageNamed:@"defaultUserIcon"]];
    
    self.gifView.hidden = !topicItem.is_gif;
    
    if (topicItem.isBigPicture) { // 如果是长图
        self.seeBigPictureButton.hidden = NO;
        self.imageView.contentMode = UIViewContentModeTop;
        self.imageView.clipsToBounds = YES;
    }else{
        self.seeBigPictureButton.hidden = YES;
        self.imageView.contentMode = UIViewContentModeScaleToFill;
        self.imageView.clipsToBounds = NO;
    }
}

- (void)seeBigPicture{
    Kylin_SeeBigPictureViewController *vc = [[Kylin_SeeBigPictureViewController alloc]init];
    vc.topicItem = self.topicItem;
    UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
    [rootVC presentViewController:vc animated:YES completion:nil];
}
@end
